/**
 * @author Nicole Nelson
 */

var toAdd = false;
var currentOp;
var currentValue;

/*
 * Handles When the C (Clear) button has been Pressed
 */
function clearPressed()
{
	toAdd = false;
	currentOp = '!';
	currentValue = 0;
	document.getElementById("answer").value = '0';
}

/*
 * Handles when a Number is pressed 
 */
function number(numPressed)
{
	if(toAdd && document.getElementById("answer").value.length < 17)
		document.getElementById("answer").value = document.getElementById("answer").value + numPressed;
	else if (!toAdd)
	{
		toAdd = true;
		document.getElementById("answer").value = numPressed;
	}
}

/*
 * Handles when the decimal is pressed
 */
function decimal()
{
	var current = document.getElementById("answer").value;
	if (current.indexOf(".") == -1 && current.length < 17)
		current = current.toString() + ".";
	document.getElementById("answer").value = current;
}

/*
 * Handles when an operation button is pressed
 */
function operation(op)
{
	switch(currentOp)
	{
		case '+': currentValue = currentValue + parseFloat(document.getElementById("answer").value);
			break;
		case '-': currentValue = currentValue - parseFloat(document.getElementById("answer").value);
			break;
		case '*': currentValue = currentValue * parseFloat(document.getElementById("answer").value);
			break;
		case '/': currentValue = currentValue / parseFloat(document.getElementById("answer").value);
			break;
		default: currentValue = parseFloat(document.getElementById("answer").value);
			break;
	}
	currentOp = op;
	document.getElementById("answer").value = currentValue.toString().substring(0,17);
	toAdd = false;
}